<{if false&&!$env.cookie.MEMBER}>
<script>
/*
快速 注册登陆 
@author litie[aita]shopex.cn
  [c] shopex.cn  
*/
   window.addEvent('load',function(){
         var curLH = location.href;
         
         if(["-?login\.html","-?signup\.html","-?loginBuy\.html"].some(function(r){
         //if(["-?loginBuy\.html"].some(function(r){
                //return curLH.test(new RegExp(r));
            })){return false;}
         var MiniPassport = new Object(); 
         var miniPassportDialog = new Element('div',{'class':'dialog mini-passport-dialog'}).set('html',$E('#dialog-theme').get('value').substitute({
                      title:'',
                      content:''
                  })).setStyles({
                      display:'none',
                      width:0
                  }).adopt(new Element('iframe',{src:'javascript:void(0);',styles:{position:'absolute',
                                                                                       zIndex:-1,
                                                                                       border:'none',
                                                                                       top:0,
                                                                                       left:0,
                                                                                       'filter':'alpha(opacity=0)'
                                                                                       },width:'100%',height:'100%'})).inject(document.body);
 
         var mpdSize = {
              loginBuy:{width:570},
              signup:{width:600},
              login:{width:570},
              chain:{width:450}              
         };
         
         $extend(MiniPassport,{
               show:function(from,options){
                  var handle = this.handle = from;
                  
                  options = this.options = options ||{};
                 
                var remoteURL = options.remoteURL||(handle?handle.get('href'):false);
                var act ="login";
               
                  
                 var fxValue  = mpdSize[act];
                     fxValue.opacity = 1;
                  
                  if(miniPassportDialog.style.display=='none'){
                        var _styles  = {display:'block'};
                      
                        miniPassportDialog.setStyles(_styles);
                  }
                  miniPassportDialog.getElement('.dialog-content').empty();
                  miniPassportDialog.setStyles(fxValue).amongTo(window);
                
               
            
                  $pick(this.request,{cancel:$empty}).cancel();
                       this.request = new Request.HTML({
											url:remoteURL,
											update:miniPassportDialog.getElement('.dialog-content').set('html','&nbsp;&nbsp;<{t}>正在加载...<{/t}>'),
											method:'get',
											data:$H({mini_passport:1}),
											onFailure:function(){
														MiniPassport.hide();window.location.reload();
											},
											onSuccess:function(){
														MiniPassport.onload.call(MiniPassport);
														MiniPassport.onload.call(MiniPassport);
											}}).send();
                
                  
               },
               hide:function(chain){
                  miniPassportDialog.getElement('.dialog-content').empty();
                
                       miniPassportDialog.hide();
                       if($type(chain)=='function'){chain.call(this)}
                       miniPassportDialog.eliminate('chain');
                       miniPassportDialog.eliminate('margedata');
                      
               },
               onload:function(){

                   var dialogForm = miniPassportDialog.getElement('form');
                   miniPassportDialog.retrieve('margedata',[]).each(function(item){
                               item.t =  item.t||'hidden';
                               
                               new Element('input',{type:item.t,name:item.n,value:item.v}).inject(dialogForm);
                       });
                    
                       
                   dialogForm.removeEvents('submit').addEvent('submit',function(e){
                       
                       e.stop();
                       var form = this;
                       if(!MiniPassport.checkForm.call(MiniPassport))return MessageBox.error('<{t}>请完善必填信息!<{/t}>');
                       new Request({
                        method:form.get('method'),
                        url:form.get('action') + (form.get('action').test(/\.html/) ? '?mini=1' : '/mini/1'),
                        onRequest:function(){
                           form.getElement('input[type=submit]').set({disabled:true,styles:{opacity:.4}});
                       },onFailure:function(){
                            MessageBox.error('shibai!');return false;
                       }
                       ,onComplete:function(re){
                              form.getElement('input[type=submit]').set({disabled:false,styles:{opacity:1}});
                              var _re = [];
                              re.replace(/\\?\{([^{}]+)\}/g, function(match){
                                        if (match.charAt(0) == '\\') return _re.push(JSON.decode(match.slice(1)));
                                        _re.push(JSON.decode(match));
                              });
                              
                              var errormsg = [];
                              var plugin_url;
                            
                              _re.each(function(item){
                                  
                                  if(item.status =='failed'){
                                      errormsg.push(item.msg);
                                  }
                                  if(item.status =='plugin_passport'){
                                      plugin_url = item.url;
                                  }
                              });

                              if(errormsg.length)return MessageBox.error(errormsg.join('<br/>'));
                              if(plugin_url){
                                  MiniPassport.hide.call(MiniPassport,$pick(miniPassportDialog.retrieve('chain'),function(){
                                       var current_url = window.location.href;
                                       MessageBox.success('<{t}>正在转向...<{/t}>');
                                       if(current_url == plugin_url) location.reload();
                                       else location.href = plugin_url;
                                  
                                  }));
                              }else{
                                  MiniPassport.hide.call(MiniPassport,$pick(miniPassportDialog.retrieve('chain'),function(){
                                     //location.href = 'http://localhost/current/src/passport-create.html';
                                  
                                  }));
                              }
                       
                       }}).send(form);
                   
                   });
                   miniPassportDialog.getElement('.close').addEvent('click',this.hide.bind(this)); 
                   miniPassportDialog.amongTo(window);
                  
               
               },
               checkForm:function(){
                    var inputs = miniPassportDialog.getFormElements();
                    var ignoreIpts = $$(miniPassportDialog.getElements('form input[type=hidden]'),miniPassportDialog.getElements('form input[type=submit]'));
                    ignoreIpts.each(inputs.erase.bind(inputs));
                    
                    if (!validate(miniPassportDialog.getElement('form'))) {
                      return false;
                    }
                   
                    return true;
               
               }
               
         });
   

     /*统一拦截*/
     $(document.body).addEvent('click',function(e){
            if(Cookie.get('UNAME'))return true;
            
            var tgt = $(e.target);
            href = location.href;
            if(href.test(/-?passport/)){
                return true;
            }
            if(!tgt.match('a'))tgt = tgt.getParent('a');
            
            if((!tgt)||!tgt.match('a'))return;
            /**/
            if(tgt.href.test(/-?login/)||tgt.href.test(/-?signup/)){
                //return true;
                e.stop();
                return MiniPassport.show(tgt);
                 
            }
            //*/
            if(tgt.href.test(/\/[\?]?member/i) || tgt.href.test(/\/[\?]?passport/i)){
                if(tgt.href.indexOf('-lost') == -1)
                {
              e.stop(); 
              MiniPassport.show(tgt,{remoteURL:'<{link app="b2c" ctl="site_passport" act="login"}>'});
              miniPassportDialog.store('chain',function(){
                    
                    MessageBox.success('<{t}>会员认证成功,正在进入...<{/t}>');
                    location.href= '<{link app="b2c" ctl="site_member" act="index"}>';
              
              }); 
                } 
                           
            }
     });
     
     
      
     
     
     /*checkout*/
     $$('form[action$=checkout.html]').removeEvent('submit').addEvent('submit',function(e){
            if($('error_str')) {
                MessageBox.success($('error_str').get('text'));return false;
            }
            if(Cookie.get('UNAME'))return this.submit();
            
            <{if !$env.cookie.MEMBER && $guest_enabled=='true'}> 
            if(Cookie.get('S[ST_ShopEx-Anonymity-Buy]')==='true') {
                location.href = '<{link app="b2c" ctl="site_cart" act="checkout"}>';
                return;
            }
            
            Cookie.set('S[ST_ShopEx-Anonymity-Buy]', 'true', {path:'/'});
            
            <{/if}>
            
            e.stop();
            var form = this;
            MiniPassport.show(this,{remoteURL:'<{link app="b2c" ctl="site_cart" act="loginBuy"}>'});
            if(this.get('extra') == 'cart'){
                miniPassportDialog.store('margedata',[{t:'hidden',n:'regType',v:'buy'}]);
            }
            miniPassportDialog.store('chain',function(){
                    MessageBox.success('<{t}>正在转入...<{/t}>');
                    form.submit();
              });   
     
     
     });
   
   });
</script>


<{/if}>



<script type="text/javascript">
var __time_out = 1000;//Shop.set.refer_timeout;
window.addEvent('domready',function(){

    
     /*checkout*/
     $$('form[action$=checkout.html]').removeEvent('submit').addEvent('submit',function(e){
            if($('error_str')) {
                MessageBox.success($('error_str').get('text'));return false;
            }
            if(Cookie.get('UNAME'))return this.submit();
            
            <{if !$env.cookie.MEMBER && $guest_enabled=='true'}> 
            if(Cookie.get('S[ST_ShopEx-Anonymity-Buy]')==='true') {
                location.href = '<{link app="b2c" ctl="site_cart" act="checkout"}>';
                return;
            }
            
            Cookie.set('S[ST_ShopEx-Anonymity-Buy]', 'true', {path:'/'});
            
            <{/if}>
            
            e.stop();
            var form = this;
            MiniPassport.show(this,{remoteURL:'<{link app="b2c" ctl="site_cart" act="loginBuy"}>'});
            if(this.get('extra') == 'cart'){
                miniPassportDialog.store('margedata',[{t:'hidden',n:'regType',v:'buy'}]);
            }
            miniPassportDialog.store('chain',function(){
                    MessageBox.success('<{t}>正在转入...<{/t}>');
                    form.submit();
              });   
     
     
     });
   
   
    var ReferObj =new Object();
    $extend(ReferObj,{
        serverTime:<{$smarty.now}>,
        init:function(){        
            var FIRST_REFER=Cookie.get('S[FIRST_REFER]');
            var NOW_REFER=Cookie.get('S[NOW_REFER]');               
            var nowDate=this.time=this.serverTime*1000;                     
            if(!window.location.href.test('#r-')&&!document.referrer||document.referrer.test(document.domain))return;               
            if(window.location.href.test('#r-'))Cookie.dispose('S[N]'); 
            if(!FIRST_REFER){
            
                if(NOW_REFER){  
                    this.writeCookie('S[FIRST_REFER]',NOW_REFER,this.getTimeOut(JSON.decode(NOW_REFER).DATE));
                }else{                      
                    this.setRefer('S[FIRST_REFER]',__time_out);
                }
            }
            this.setRefer('S[NOW_REFER]',__time_out);
            this.createGUID();
        },
        getUid:function(){
            var lf=window.location.href,pos=lf.indexOf('#r-');
            return pos!=-1?lf.substr(pos+4):''; 
        },
        getRefer:function(){
            return document.referrer?document.referrer:'';
        },
        setRefer:function(referName,timeout){   
            var uid=this.getUid(),referrer=this.getRefer();
            var data={'ID':uid,'REFER':referrer,'DATE':this.time};
            
            if('S[NOW_REFER]'==referName){      
                var refer=JSON.decode(Cookie.get('S[FIRST_REFER]'));    
                if(uid!=''&&refer&&refer.ID==''){                       
                    var fdata={'ID':uid,'REFER':refer.REFER,'DATE':refer.DATE};
                    this.writeCookie('S[FIRST_REFER]',JSON.encode(fdata),this.getTimeOut(refer.DATE));                          
                }else if(uid==''){                  
                    $extend(data,{'ID':refer.ID});
                }   
            }   
            //alert(SON.encode(data));
            Cookie.set(referName,JSON.encode(data),{duration:(__time_out||15)});
        },              
        getTimeOut:function(nowDate){           
            var timeout=nowDate+__time_out*24*3600*1000;
            var date=new Date(timeout);
            return date;
        },
        writeCookie:function(key,value,timeout){
            document.cookie=key+ '=' + value+'; expires=' + timeout.toGMTString();  
        },
        createGUID:function(){
            var GUID = (function(){
                var S4=function(){
                    return (((1+Math.random())*0x10000)|0).toString(16).substring(1);
                };
                return (S4()+S4()+"-"+S4()+"-"+S4()+"-"+S4()+"-"+S4()+S4()+S4()).toUpperCase();
            })();
            Cookie.set('S[N]',GUID,{duration:3650});
        }
    });
    ReferObj.init();
});
    
        
  </script>


<script>
var Shop = <{$shopDefine}>;
</script>
<{if $openid_open == 'true'}>
<script>
(function(){
 RemoteLogin={
        init:function(){
             if(!$$('.trust__login')||$ES('.trustdialog').length)return;    
             $$('.trust__login').removeEvents('click').addEvent('click',this.show.bind(this));
        },    
        show:function(){
             new Request({
				url:'<{link app="openid" ctl="site_trust" act="trust_login"}>',
			    onRequest:function(){
                    var winWidth = 440,
                    winHeight = 330,
                    winTop=(screen.availHeight - winHeight)/2,
                    winLeft=(screen.availWidth - winWidth)/2,
                    param0 = "toolbar=no,menubar=no,scrollbars=no,resizable=no,location=no, status=no,directories=no", 
                    params = "top=" + winTop + ",left=" + winLeft + ",width=" + winWidth + ",height=" + winHeight + "," + param0; 
                    this.opt = params;
                    //this.title = "信任登陆";
                    /*
                      this.loginDialog = new Element('div',{'class':'dialog trustdialog','id':'trust_footer_login'}).set('html',$E('#template-modal .dialog').get('html').substitute({
                      title:'信任登录',
                      content:'<iframe src="" id="RemoteFrm" width="100%" height="90%" frameborder="0" styles="border:none;background: none repeat scroll 0% 0% transparent; "></iframe>'
                       })).setStyles({display:'none',width:0}).inject(document.body);

                      this.loginDialog.getElement('.dialog-close-btn').addEvent('click',function(){$('trust_footer_login').destroy();});  
					  this.loginDialog.setStyles({width:440,height:330,display:'block'}).amongTo(window);
                  */
                  },
                onComplete:function(e){
                     if(e){
                          var remotesrc='http://openid.ecos.shopex.cn/index.php?certi_id=<{$cert_id}>&callback_url=<{link app="openid" ctl="site_trust" act="other_login" full="1"}>&refertype=ecstore';
                      }else{
                         var remotesrc='<{link app="openid" ctl="site_trust" act="error"}>';
                      }
                     //this.loginDialog.getElement('iframe').src=remotesrc;
                      //location.href = remotesrc;
                      var NewWin = open(remotesrc,"信任登陆",this.opt); 
                      //NewWin.document.title = "信任登陆";
                }
            }).post();
        }       
    };
    RemoteLogin.init();
})();
</script>
<{/if}>


<script>
/*
迷你购物车
@author litie[aita]shopex.cn
  [c] shopex.cn
*/

 window.addEvent('domready',function(){
      miniCart={
           'show':function(target){
               var _this=this, dialog  = this.dialog =$pick($('mini-cart-dialog'),new Element('div',{'class':'dialog mini-cart-dialog','id':'mini-cart-dialog'}).setStyles({width:300}).inject(document.body));
                this.dialog.setStyles({
                         top:target.getPosition().y+target.getSize().y,
                         left:target.getPosition().x
                    }).set('html',

                  $E('#dialog-theme').get('value').substitute({

                      title:'<{t}>正在加入购物车<{/t}>',
                      content:'<{t}>正在加入购物车...<{/t}>'
                  })

               ).show();

               document.addEvent('click',function(e){
				  (function(){_this.hide();}).delay(100);
				  document.removeEvent('click',arguments.callee);
               });

           },
		   'hide':function(){
				 try{
				 if(this.dialog)this.dialog.destroy();
				 }catch(e){}
		   },
           'load':function(){
              var params=Array.flatten(arguments).link({
                  'remoteURL':String.type,
                  'options':Object.type
              });
              params.options.data = params.options.data?params.options.data.toQueryString()+'&mini_cart=true':'&mini_cart=true';
              var opts=params=$extend({
                 url:params.remoteURL,
                 method:'post',
                 onRequest:function(){
                     //this.dialog.getElement('.title').set('html','正在加入购物车');

                 }.bind(this),
                 onSuccess:function(re){
                     //this.dialog.getElement('.title').set('html','<img src="statics/icon-success.gif" />成功加入购物车');
                     this.dialog.getElement('.dialog-content').set('html',re);
                     $$('.cart-number').set('text',Cookie.read('S[CART_COUNT]')||0);
					
					 if($E('.minicart_box')&&$E('.minicart_box').get('show_gallery')){
						$E('.minicart_box').fireEvent('_show');  //迷你购物车
					 }
				 }.bind(this),
                 onFailure:function(xhr){
                     this.dialog.remove();
                     MessageBox.error("<{t}>加入购物车失败.<{/t}><br /><ul><li><{t}>可能库存不足.<{/t}></li><li><{t}>或提交信息不完整.<{/t}></li></ul>");
                 }.bind(this)
              },params.options||{});
              if(!params.url)return false;
              miniCart.show(opts.target);
              new Request(opts).send();
           },
		   init:function(){
			   var linktocart;	
			   if(linktocart=$$('a[target=_dialog_minicart]')){
				   if(linktocart.length){
						linktocart.addEvent('click',function(e){
							 e.stop();
							 if(!this.hasClass('hasSpec'))
							 miniCart.load([{url:this.href,target:this}]);
						});
				   }
			   };
		   }
     };
	 
	 miniCart.init();

   var formtocart,btnbuy;

   if(formtocart=$E('form[target=_dialog_minicart]')){
       formtocart.addEvent('submit',function(e){
           e.stop();
           miniCart.load([{
               url:this.action,
               method:this.method,
               data:this,
               target:this.getElement('input[value=<{t}>加入购物车<{/t}>]')
           }]);
       });
   };
   /*for  goods which has specs*/
   if(btnbuy=$E('#goods-viewer form[target=_dialog_minicart] .btn-buy')){

      btnbuy.removeEvents('click').addEvent('click',function(e){
          e.stop();
          if(this.retrieve('tip:text'))return false;
          this.blur();
          this.form.fireEvent('submit',e);

      });

   };
	
});

</script>



<script>
if($ES('.GoodsSearchWrap .itemsList')){
	$ES('.GoodsSearchWrap .itemsList').addEvent('showSpec',function(e,gid){
		 e.stop();
		 var dialog= new Dialog('<{$request_url}>',{target:this,method:'get',data:'gid='+this.get('product'),rela:$('AllWrap'),
			onPosition:function(){	
				this.body.getElement('.arrowleft').addClass('arrowright').removeClass('arrowleft');
			},
			onSuccess:function(){
			   $E('form',this.body).addEvent('submit',function(e){
					miniCart.load([{
					   url:this.action,
					   method:this.method,
					   data:this,
					   target:this.getElement('.updateBtn')
				   }]);				
			   });
			},
			onClose:function(){
				miniCart.hide();
			}
		});       
	});

	$ES('.GoodsSearchWrap .hasSpec').addEvent('click',function(e){
		 this.getParent('.itemsList').fireEvent('showSpec',e);
	});
}
</script>

<textarea id='dialog-theme' style="display:none">
     <div class='dialog-title clearfix' style="height:24px">
          <div class='title span-auto'>{title}</div>
          <div class='dialog-close-btn' isCloseDialogBtn ><span></span></div>
    </div>
    <div class='dialog-content'> {content} </div>
</textarea>

